package com.imooc.mall.model.common;

import com.google.common.collect.Sets;
import com.imooc.mall.model.exception.ImoocMallException;
import com.imooc.mall.model.exception.ImoocMallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component          //使用Component，spring才知道value
public class Constant {
    public static final String SALT="sdfjk234kui},?";
    public static final String IMOOC_MALL_USER="imooc_mall_user";


    public static String FILE_UPLOAD_DIR;

    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir){
        FILE_UPLOAD_DIR=fileUploadDir;
    }

    public interface ProductListOrderBy{
        Set<String> PRICE_DESC_ASC= Sets.newHashSet("price desc","price asc");
    }

    public interface SaleStatus{
        int NOT_SALE=0;//0商品下架
        int SALE=1;//1商品上架
    }

    public interface Cart{
        int UN_CHECKED=0;//购物车未选中
        int CHECKED=1;//购物车选中
    }

    public enum OrderStatusEnum{
        CANCELED(0,"用户取消"),
        NOT_PAID(10,"未付款"),
        PAID(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易完成");


        private Integer code;
        private String value;

        OrderStatusEnum(Integer code, String value) {
            this.code = code;
            this.value = value;
        }

        public static OrderStatusEnum codeOf(Integer code){
            for(OrderStatusEnum orderStatusEnum:values()){
                if(orderStatusEnum.getCode()==code){
                    return orderStatusEnum;
                }
            }
            throw new ImoocMallException(ImoocMallExceptionEnum.NOT_ENUM);
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

}
